import {Message} from 'element-ui'

export default function ({$axios, redirect}) {
  $axios.interceptors.response.use(
    (response) => {
      if (response.data.success == false) {
        console.log('请求失败')
        return
      }
      // console.log(response)
      return response
    },
    (err) => {
      if (err && err.response) {
        err.message = err.response.data.error
        switch (err.response.status) {
          case 401:
            err.message = '请您登录'
            break
        }
      } else {
        err.message = '连接服务器失败!'
      }
      // Message.error(err.message)
      return Promise.reject(err)
    }
  )
}
